package org.caiotte.service.impl;


import org.caiotte.domain.Employee;
import org.caiotte.mapper.EmployeeMapper;
import org.caiotte.query.EmployeeQuery;
import org.caiotte.service.IEmployeeService;
import org.caiotte.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl implements IEmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    @Transactional
    public void save(Employee employee) {
        employeeMapper.save(employee);
    }

    @Override
    @Transactional
    public void update(Employee employee) {
        employeeMapper.update(employee);
    }

    @Override
    @Transactional
    public void removeById(Long id) {
        employeeMapper.deleteById(id);
    }

    @Override
    public List<Employee> queryAll() {
        return employeeMapper.loadAll();
    }

    @Override
    public Employee queryById(Long id) {
        return employeeMapper.loadById(id);
    }

    @Override
    public PageList<Employee> queryPage(EmployeeQuery query) {
        //查询总条数
        Long total = employeeMapper.queryCount(query);
        //查询当前页的数据
        List<Employee> rows = employeeMapper.queryData(query);
        return new PageList<Employee>(total,rows);
    }

    @Override
    public void batchRemove(List<Long> ids) {
        employeeMapper.batchRemove(ids);
    }
}
